<?php
/**
 *
 * @package    gadgets
 * @subpackage feature
 * @author     Daniel Botelho <botelho.daniel@gmail.com>
 */
class GadgetsFlash
{
  const DEFAULT_CLASS = 'gadgets.flash';
  
  /**
   * Detects Flash Player and its major version.
   */
  public static function getMajorVersion($appendable=false)
  {
  	OSConfig::importFlash();
    return StringUtil::appendableString("gadgets.flash.getMajorVersion()",$appendable);
  }
  
  private static function executeFlash($type,JSVariable $swfContainer,FlashObject $flashObject,$appendable)
  {
  	$url = $flashObject->getURL();
  	$update = $swfContainer->getName();
  	$version = $flashObject->getFlashVersion();
  	$params = "{";
  	foreach ($flashObject->getParams() as $key => $value ) {
  		$params .= $key.' : "'.$value.'", ';
  	}
  	$params = substr($params,0, -2);
  	
  	$params .= "}";
  	return StringUtil::appendableString("gadgets.flash.$type($url, $update,$version , $params)",$appendable);
  }
  /**
   * Injects a Flash file into the DOM tree.
   *
   * @param JSVariable $swfContainer The javascript variable the will hold the div that will be updated
   * @param FlashObject $flashObject The Flash object that will be loaded
   * @param boolean $appendable If this method will be appended or not
   * @return string HTML string
   */
  public static function embedFlash(JSVariable $swfContainer,FlashObject $flashObject,$appendable=false)
  {
  	OSConfig::importFlash();
    return GadgetsFlash::executeFlash('embedFlash',$swfContainer,$flashObject,$appendable);
  }
  
  public static function embedCachedFlash(JSVariable $swfContainer,FlashObject $flashObject,$appendable=false)
  {
  	//FIXME: não implementado porque não funciona em nehum container
  	throw new Exception('Not supported yet!');
  	OSConfig::importFlash();
    //return GadgetsFlash::executeFlash('embedCachedFlash',$swfContainer,$flashObject,$appendable);
  }
}